package com.ztf666.articlereview.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * @author z
 * @date 2022/2/21 下午3:36
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)//只解析不为空的数据,注意"" 也算空,也就是只返回有效数据
public class R {
    /**
     * 状态码
     */
    private int code;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 携带的数据
     */
    private Object data;

    public static R setOK(){
        return setOK(null);
    }
    public static R setOK(Object data){
        return setError(0, "成功", data);

    }

    public static R setError(int code, String msg) {
        return setError(code, msg, null);
    }

    public static R setError(int code, String msg, Object data) {
        R result = new R();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
